**************************************************************************************************
*** This do file creates the replication results for 
*** The �Peer-Effect� in Counterterrorist Policies                   	 					 	*/
*** Eric Neumayer (LSE), Thomas Pluemper (U of Essex) and Mariaelisa Epifanio (U of Warwick)      */
*** 																							*/
*** Published in: International Organization, 68 (1), 2014, pp. 209-232											*/
**************************************************************************************************
**************************************************************************************************
/* Note: You have to change "local DIR" to the directory you copy the original stata files contained 	*/
/* in the zip file and then run the do file. 
/* You must have Stata version 12 or higher installed													*/
**************************************************************************************************
*/

version 11
drop _all
clear matrix
clear mata


***********************************************************************************
local DIR = "C:\Research\Conflict\ITERATE\Data from Mariaelisa\"  /*change relative path to the directory where the files are located */
cd "`DIR'"
***********************************************************************************

use "Article for IO (counter-terrorism)", clear

* figure 1
capture drop SL_peers_exp
gen SL_peers_exp=exp(sl_pi_lnsumtot_wpeers_tots)-1
label var SL_peers_exp "SL (peers)"
capture drop SL_nonpeers_exp
gen SL_nonpeers_exp=exp(sl_pi_lnsumtot_wnonpeers_tots)-1
label var SL_nonpeers_exp "SL (non-peers)"
label var sumtot "Regulations"

twoway line sumtot SL_peers_exp SL_nonpeers_exp year if year>=2000 & year<=2008, by(threat_level country, note("") caption("") b1title("")) xlabel(2000  2002  2004 2006 2008) lstyle(solid solid solid) lpattern(solid dash dot) lcolor(black)


*** Main estimations, table 2

* model 1
xi: poisson sumtot icsumtot gdppcconst gov_left1 gov_right1 predinc_total sl_pi_lnsumtot_wpeers_tots sl_pi_lnsumtot_wnonpeers_tots year if year>2000, cluster(country)
margins, at((mean) _all (p25) sl_pi_lnsumtot_wpeers_tots )
margins, at((mean) _all (p75) sl_pi_lnsumtot_wpeers_tots )
margins, at((mean) _all (p25) predinc_total )
margins, at((mean) _all (p75) predinc_total )
margins, at((mean) _all (p95) predinc_total )

* model 2
capture drop sumtotasobservedann_3grps
egen sumtotasobservedann_3grps=mean(sumtot), by(i_pi_totsum_rank_3grps year)
capture drop belowasobservedann_3grps
gen belowasobservedann_3grps=0
replace belowasobservedann_3grps=. if sumtot==.
replace belowasobservedann_3grps=1 if sumtot<sumtotasobservedann_3grps
capture drop sl_pi_wpeers_above sl_pi_wpeers_below
gen sl_pi_wpeers_above=sl_pi_lnsumtot_wpeers_tots*(1-belowasobservedann_3grps)
gen sl_pi_wpeers_below=sl_pi_lnsumtot_wpeers_tots*(belowasobservedann_3grps)
poisson sumtot icsumtot gdppcconst gov_left1 gov_right1 predinc_total belowasobservedann_3grps##c.sl_pi_lnsumtot_wpeers_tots sl_pi_lnsumtot_wnonpeers_tots year if year>2000, cluster(country)
margins, at((mean) _all (p25) sl_pi_lnsumtot_wpeers_tots) over(belowasobservedann_3grps)
margins, at((mean) _all (p75) sl_pi_lnsumtot_wpeers_tots) over(belowasobservedann_3grps)


*** Robustness tests, table 3

* model 3: clustering on peer group level
xi: poisson sumtot icsumtot gdppcconst gov_left1 gov_right1 predinc_total sl_pi_lnsumtot_wpeers_tots sl_pi_lnsumtot_wnonpeers_tots year if year>2000, cluster(threat_level)


* model 4: LDV and country fixed effects
tsset
capture drop lsumtot
gen lsumtot=l.sumtot
xi: xtpoisson sumtot lsumtot gdppcconst gov_left1 gov_right1 predinc_total sl_pi_lnsumtot_wpeers_tots sl_pi_lnsumtot_wnonpeers_tots year if year>2000, fe

* model 5: Include "cultural peer"-link variables
xi: poisson sumtot icsumtot gdppcconst gov_left1 gov_right1 predinc_total sl_pi_lnsumtot_wpeers_tots sl_pi_lnsumtot_wnonpeers_tots sl_lnsumtot_w_cult_grp2_peers sl_lnsumtot_w_cult_grp2_nonpeers year if year>2000, cluster(country)

* model 6: Year fixed effects
xi: poisson sumtot icsumtot gdppcconst gov_left1 gov_right1 predinc_total sl_pi_lnsumtot_wpeers_tots sl_pi_lnsumtot_wnonpeers_tots i.year if year>2000, cluster(country)

* model 7: Include SL with unitary and CINC weights 
xi: poisson sumtot icsumtot gdppcconst gov_left1 gov_right1 predinc_total sl_pi_lnsumtot_wpeers_tots sl_pi_lnsumtot_wnonpeers_tots sl_lnsumtot_unitary_tots sl_lnsumtot_cinc_tots year if year>2000, cluster(country)

* model 8: Separate spatial lags for the groups
replace sl_pi_lnsumtot_wi_k_low_tots=0 if sl_pi_lnsumtot_wi_k_low_tots==.
replace sl_pi_lnsumtot_wi_k_mid_tots=0 if sl_pi_lnsumtot_wi_k_mid_tots==.
replace sl_pi_lnsumtot_wi_k_high_tots=0 if sl_pi_lnsumtot_wi_k_high_tots==.
xi: poisson sumtot icsumtot gdppcconst gov_left1 gov_right1 predinc_total sl_pi_lnsumtot_wi_k_low_tots sl_pi_lnsumtot_wi_k_mid_tots sl_pi_lnsumtot_wi_k_high_tots sl_pi_lnsumtot_wnonpeers_tots year if year>2000, cluster(country)
test sl_pi_lnsumtot_wi_k_low_tots= sl_pi_lnsumtot_wi_k_mid_tots= sl_pi_lnsumtot_wi_k_high_tots , mtest

* model 9: Groupings based on actual incidents
xi: poisson sumtot icsumtot gdppcconst gov_left1 gov_right1 actualincidents_total sl_ai_lnsumtot_wpeers_tots sl_ai_lnsumtot_wnonpeers_tots year if year>2000, cluster(country)

* model 10: Groupings based on predicted killings
xi: poisson sumtot icsumtot gdppcconst gov_left1 gov_right1 predkill_total sl_pk_lnsumtot_wpeers_tots sl_pk_lnsumtot_wnonpeers_tots year if year>2000, cluster(country)

* model 11: Groupings based on actual killings
xi: poisson sumtot icsumtot gdppcconst gov_left1 gov_right1 actualkillings_total sl_ak_lnsumtot_wpeers_tots sl_ak_lnsumtot_wnonpeers_tots year if year>2000, cluster(country)

* model 12: Groupings based on actual incidents (1996 to 2000)
xi: poisson sumtot icsumtot gdppcconst gov_left1 gov_right1 actualincidents_total  sl_ai_lnsumtot_wpeers_pre911 sl_ai_lnsumtot_wnonpeers_pre911 year if year>2000, cluster(country)

